Skip to content

fix: skip IPAM init for empty IP annotation and handle nil IPRangeList#6296

Merged
zbb88888 merged 1 commit intokubeovn:masterfrom
zbb88888:fix-gw-ip-is-empty
Feb 11, 2026
Merged

fix: skip IPAM init for empty IP annotation and handle nil IPRangeList#6296
zbb88888 merged 1 commit intokubeovn:masterfrom
zbb88888:fix-gw-ip-is-empty

Conversation

@zbb88888
Copy link
Copy Markdown
Collaborator

  • Skip IPAM initialization when pod IP annotation is empty, log warning instead
  • Make IPRangeList.Len() nil-safe to prevent panic in GetSubnetIPRangeString
  • Add unit test for nil IPRangeList.Separate() behavior

Pull Request

What type of this PR

Examples of user facing changes:

  • Bug fixes

两个问题,好像都是空 ip 问题

E0211 15:34:18.554217       7 init.go:457] failed to init pod vpc-nat-gw-fip-subnet-69897ff101ca5d975cb0fdbb-0.kube-system address : invalid IP address ""
I0211 15:34:18.554251       7 ipam.go:103] allocate v4 10.1.255.254, mac 0e:c3:b7:e6:ad:7f for kube-system/vpc-nat-gw-fip-subnet-69897ff101ca5d975cb0fdbb-0 from subnet subnet-69897ff101ca5d975cb0fdbb

E0211 15:58:51.084850       7 panic.go:262] "Observed a panic" panic="runtime error: invalid memory address or nil pointer dereference" panicGoValue="\"invalid memory address or nil pointer dereference\"" stacktrace=<
	goroutine 1259 [running]:
	k8s.io/apimachinery/pkg/util/runtime.logPanic({0x55fc4ac8c2c8, 0xc000ee5f20}, {0x55fc4a6c3c80, 0x55fc4c8882e0})
		k8s.io/apimachinery@v0.34.3/pkg/util/runtime/runtime.go:132 +0xbc
	k8s.io/apimachinery/pkg/util/runtime.handleCrash({0x55fc4ac8e188, 0xc00052fc70}, {0x55fc4a6c3c80, 0x55fc4c8882e0}, {0x0, 0x0, 0xc00127b4c0?})
		k8s.io/apimachinery@v0.34.3/pkg/util/runtime/runtime.go:107 +0x116
	k8s.io/apimachinery/pkg/util/runtime.HandleCrashWithContext({0x55fc4ac8e188, 0xc00052fc70}, {0x0, 0x0, 0x0})
		k8s.io/apimachinery@v0.34.3/pkg/util/runtime/runtime.go:78 +0x5a
	panic({0x55fc4a6c3c80?, 0x55fc4c8882e0?})
		runtime/panic.go:783 +0x132
	github.com/kubeovn/kube-ovn/pkg/ipam.(*IPRangeList).Len(...)
		github.com/kubeovn/kube-ovn/pkg/ipam/ip_range_list.go:88
	github.com/kubeovn/kube-ovn/pkg/ipam.(*IPRangeList).Separate(0xc001797d88, 0x0?)
		github.com/kubeovn/kube-ovn/pkg/ipam/ip_range_list.go:215 +0x32
	github.com/kubeovn/kube-ovn/pkg/ipam.(*IPAM).GetSubnetIPRangeString(0xc0008ff8c0, {0xc00087c460, 0x1b}, {0xc000ee4660?, 0x55fc486eada6?, 0xc0009e16c0?})
		github.com/kubeovn/kube-ovn/pkg/ipam/ipam.go:432 +0x1c7
	github.com/kubeovn/kube-ovn/pkg/controller.(*Controller).calcSubnetStatusIP(0xc0000ea008, 0xc001b8f688)
		github.com/kubeovn/kube-ovn/pkg/controller/subnet_status.go:193 +0x347
	github.com/kubeovn/kube-ovn/pkg/controller.(*Controller).handleUpdateSubnetStatus(0xc0000ea008, {0xc001cc1c60, 0x1b})
		github.com/kubeovn/kube-ovn/pkg/controller/subnet_status.go:107 +0x435
	github.com/kubeovn/kube-ovn/pkg/controller.processNextWorkItem[...].func1(0x81fb720eb16c48ee, {0x55fc49623952, 0x17?}, 0x55fc4ac40a30, 0x55fc4ac513a0, {0xc001cc1c60, 0x1b})
		github.com/kubeovn/kube-ovn/pkg/controller/controller.go:1541 +0xb4
	github.com/kubeovn/kube-ovn/pkg/controller.processNextWorkItem[...]({0x55fc49623952, 0x17}, {0x55fc4acaa1a0, 0xc000960ca0}, 0xc001a1b600, 0x55fc4ac40a30)
		github.com/kubeovn/kube-ovn/pkg/controller/controller.go:1547 +0x7c
	github.com/kubeovn/kube-ovn/pkg/controller.(*Controller).startWorkers.runWorker[...].func46()
		github.com/kubeovn/kube-ovn/pkg/controller/controller.go:1577 +0x73
	k8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1({0x7ec6e4ccd1dc6bc7?, 0xf9ae47724f0131f4?})
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:233 +0x13
	k8s.io/apimachinery/pkg/util/wait.BackoffUntilWithContext.func1({0x55fc4ac8e188?, 0xc00052fc70?}, 0x55fc47183e94?)
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:255 +0x51
	k8s.io/apimachinery/pkg/util/wait.BackoffUntilWithContext({0x55fc4ac8e188, 0xc00052fc70}, 0xc00127bf50, {0x55fc4ac52ce0, 0xc001914120}, 0x1)
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:256 +0xe5
	k8s.io/apimachinery/pkg/util/wait.BackoffUntil(0x6b0d0c31d96c925b?, {0x55fc4ac52ce0?, 0xc001914120?}, 0xa1?, 0xc5d0b14418e6a184?)
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:233 +0x46
	k8s.io/apimachinery/pkg/util/wait.JitterUntil(0xc000ef5580, 0x3b9aca00, 0x0, 0x1, 0xc00052fc70)
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:210 +0x7f
	k8s.io/apimachinery/pkg/util/wait.Until(...)
		k8s.io/apimachinery@v0.34.3/pkg/util/wait/backoff.go:163
	created by github.com/kubeovn/kube-ovn/pkg/controller.(*Controller).startWorkers in goroutine 104
		github.com/kubeovn/kube-ovn/pkg/controller/controller.go:1345 +0x3ae9

Which issue(s) this PR fixes

Fixes #(issue-number)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zbb88888, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two critical bug fixes related to IP address management within Kube-OVN. It enhances the system's robustness by preventing errors during IPAM initialization when pod IP annotations are unexpectedly empty and by safeguarding against nil pointer dereferences in IP range list operations, ensuring more stable and reliable network resource allocation.

Highlights

  • IPAM Initialization: IPAM initialization is now skipped for pods with empty IP annotations, logging a warning instead of an error.
  • Nil-safe IPRangeList: The IPRangeList.Len() method has been made nil-safe to prevent panics when called on a nil receiver.
  • Unit Testing: A new unit test was added to verify that calling Separate() on a nil IPRangeList does not cause a panic.
Changelog
  • pkg/controller/init.go
    • Added a check to skip IPAM initialization if the IP annotation is empty, logging a warning instead.
  • pkg/ipam/ip_range_list.go
    • Modified the Len() method of IPRangeList to return 0 if the receiver is nil, preventing nil pointer dereferences.
  • pkg/ipam/ip_range_list_test.go
    • Added a new unit test to verify that calling Separate() on a nil IPRangeList does not cause a panic and returns an empty list.
Activity
  • The author identified two issues related to empty IP configurations, providing detailed stack traces from observed panics.
  • The pull request includes a standard checklist for Kube-OVN Code Style, indicating adherence to project guidelines.
  • The changes aim to fix these identified bugs, specifically addressing an 'invalid IP address' error and a 'nil pointer dereference' panic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 11, 2026

Pull Request Test Coverage Report for Build 21898049930

Details

  • 21 of 25 (84.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 22.981%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/init.go 0 4 0.0%
Totals Coverage Status
Change from base Build 21883834861: 0.03%
Covered Lines: 12504
Relevant Lines: 54409

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to prevent panics during IPAM initialization by handling empty IP annotations and makes IPRangeList.Len() nil-safe. However, the nil-safety implementation for IPRangeList is only partial; several core methods still lack nil checks on the receiver, which can lead to controller panics in common scenarios like single-stack subnet configurations. It is recommended to extend nil-safety to all methods of IPRangeList that access internal fields for better robustness.

@zbb88888 zbb88888 force-pushed the fix-gw-ip-is-empty branch 2 times, most recently from b0265ad to 818bf53 Compare February 11, 2026 08:33
- Skip IPAM initialization when pod IP annotation is empty, log warning instead
- Make IPRangeList.Len() nil-safe to prevent panic in GetSubnetIPRangeString
- Add unit test for nil IPRangeList.Separate() behavior

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
@zbb88888
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次合并请求有效地解决了两个独立的问题:一是修复了当 Pod 的 IP 注解为空时 IPAM 初始化会失败的问题,二是通过处理空的 IPRangeList 来避免空指针解引用。

pkg/controller/init.go 中的更改正确地添加了对空 IP 地址的检查,当 IP 为空时会记录警告并跳过该 Pod 网络的初始化。这是一个清晰的修复,解决了所报告的错误。

pkg/ipam/ip_range_list.go 中的修改为多个方法添加了必要的 nil 接收器检查,防止了在对空的 *IPRangeList 实例进行操作时发生 panic。这是一种很好的防御性编程实践,提高了 IPAM 模块的健壮性。pkg/ipam/ip_range_list_test.go 中附带的测试非常详尽,验证了所修改方法的 nil 安全性。

总的来说,这是一个高质量的贡献,提高了代码库的稳定性和可靠性。代码变更正确、实现良好且经过了充分的测试。

@zbb88888 zbb88888 marked this pull request as ready for review February 11, 2026 08:43
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Feb 11, 2026
@zbb88888 zbb88888 requested a review from oilbeater February 11, 2026 08:45
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 11, 2026
@zbb88888 zbb88888 merged commit a0e4135 into kubeovn:master Feb 11, 2026
76 of 77 checks passed
@zbb88888 zbb88888 deleted the fix-gw-ip-is-empty branch February 11, 2026 09:37
zbb88888 added a commit that referenced this pull request Feb 11, 2026
#6296)

- Skip IPAM initialization when pod IP annotation is empty, log warning instead
- Make IPRangeList.Len() nil-safe to prevent panic in GetSubnetIPRangeString
- Add unit test for nil IPRangeList.Separate() behavior

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
zbb88888 added a commit to kubehostvm/kube-ovn that referenced this pull request Feb 11, 2026
kubeovn#6296)

- Skip IPAM initialization when pod IP annotation is empty, log warning instead
- Make IPRangeList.Len() nil-safe to prevent panic in GetSubnetIPRangeString
- Add unit test for nil IPRangeList.Separate() behavior

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants